package com.reins.bookstore.entity;

import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import com.reins.bookstore.object.UserDTO;
import lombok.Data;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;


@Entity
@Table(name = "userAuth")
@JsonIgnoreProperties(value = {"handler","hibernateLazyInitializer","fieldHandler"})
@JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class,property = "userId")
public class UserAuth {

    @Id
    @Column(name = "user_id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer userId;
    @Column(name = "username")
    private String username;
    @Column(name = "password")
    private String password;
    @Column(name = "user_type")
    private Integer userType;
    @Column(name = "banned")
    private Integer banned;

    @JsonIgnoreProperties(value = {"userAuth"})
    @OneToMany(fetch = FetchType.LAZY,mappedBy = "userAuth")
    private List<Orders> orderses = new ArrayList<>();

    public UserAuth(UserDTO user_dto, String password){
        this.userId = user_dto.getUserId();
        this.username = user_dto.getUsername();
        this.password = password;
        this.userType = 0;  //新创建的账号默认是普通账号
        this.banned = 0;    //新创建的账号默认是非禁止状态
    }

    public UserAuth(UserDTO user_dto){
        this.userId = user_dto.getUserId();
        this.username = user_dto.getUsername();
        this.userType = 0;  //新创建的账号默认是普通账号
        this.banned = 0;    //新创建的账号默认是非禁止状态
    }

    public UserAuth(Integer userId, String username, String password, Integer userType, Integer banned) {
        this.userId = userId;
        this.username = username;
        this.password = password;
        this.userType = userType;
        this.banned = banned;
    }

    public UserAuth() {

    }

    public Integer getUserId() {
        return userId;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public Integer getBanned(){return banned;}

    public void setBanned(Integer banned){this.banned = banned;}

    public void setPassword(String password) {
        this.password = password;
    }

    public Integer getUserType() {
        return userType;
    }

    public void setUserType(Integer userType) {
        this.userType = userType;
    }
}
